<template>
  <Modal v-model="modal" :title="title">
    <div class="dealer-pointmodify-modal scroll">
       <Form ref="formValidate" :model="row" :rules="ruleValidate">
          <FormItem label="经销商名称:">
            <p>{{row.distributorName}}</p>
          </FormItem>
          <FormItem label="联系方式:">
            <p>{{row.distributorMobile}}</p>
          </FormItem>
          <FormItem label="联系人:">
            <p>{{row.distributorContact}}</p>
          </FormItem>
          <FormItem label="奖惩积分:" prop='integral'>
            <InputNumber v-model="row.integral" :precision="0" :min="-1000000" :max="1000000" style="width:120px"></InputNumber>
          </FormItem>
          <FormItem label="备注:">
            <Input :maxlength="50" placeholder="不超过50字" type="textarea" v-model="row.remark" />
          </FormItem>
       </Form>
    </div>
    <div slot="footer">
        <Button @click="modal = false" size="large" type="text">取消</Button>
        <Button :disabled="disabled" @click="onSave" type="primary" size="large">确定</Button>
    </div>
</Modal>
</template>
<script>
export default {
  data() {
    return {
      id: null,
      modal: false,
      disabled: false,
      title: '新增奖惩记录',
      row: {
        distributorName: '',
        distributorMobile: '',
        distributorContact: '',
        integral: '',
        remark: '',
        distributorContractId: null
      },
      ruleValidate: {
        integral: [
            { required: true, message: '奖惩积分在负100万到100万之间', trigger: 'blur', pattern: /^-?\d+$/ }
        ]
      }
    };
  },
  methods: {
    openModal(row) {
      this.disabled = false
      this.modal = true
      let {distributorName, distributorMobile, distributorContact} = row
      this.row = Object.assign(this.row, {distributorName, distributorMobile, distributorContact})
      this.row.distributorContractId = row.id
      this.row.integral = ''
      this.row.remark = ''
    },
    closeModal() {
      this.modal = false;
    },
    onSave() {
      this.disabled = true
      this.$refs["formValidate"].validate(valid => {
          if (valid) {
            let params = {
              distributorContractId: this.row.distributorContractId,
              integral: this.row.integral,
              remark: this.row.remark
            }
            this.$jsonPost('/distributor/integral/save', params).then(res => {
              this.$Message.success('操作成功')
              this.closeModal()
            }).catch(() => {
              this.disabled = false
            })
          } else {
            this.disabled = false
          }
      })
    }
  }
}
</script>

